/**
 * 
 */
package com.aat.dxfy.thread.demo01;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @date 2016年6月29日 下午3:08:15
 * @author 新歌<xingeking@163.com>
 * @email xingeking@163.com
 * @version v1.0
 * @function 功能是：
 * @info java spring
 * @update none
 */
public class Account3 {
	private final ReentrantLock lock = new ReentrantLock();

	private String accountNum;
	private Integer money;

	public Account3(String accountNum, Integer money) {
		super();
		this.accountNum = accountNum;
		this.money = money;
	}

	public String getAccountNum() {
		return accountNum;
	}

	public void setAccountNum(String accountNum) {
		this.accountNum = accountNum;
	}

	public Integer getMoney() {
		return money;
	}

	public void setMoney(Integer money) {
		this.money = money;
	}
	
	public void quqian(Integer quqian){
		lock.lock();
		try{
			if(money>quqian){
				System.out.println(Thread.currentThread().getName()+" 从"+accountNum+"账户取钱成功!取出金额:"+quqian);
				
				 try {
					Thread.sleep(1);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				
				 money = (money-quqian);
				System.out.println("\t"+accountNum+"账户余额为:"+money);
			}else{
				System.out.println(Thread.currentThread().getName()+" 从"+accountNum+"账户取钱失败!余额不足");
			}
		}finally{
			lock.unlock();
		}
		
		
	}

}
